package com.whale.mq.rabbit;


import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


/**
 * RabbitMq 发送消息实现类
 */
@Slf4j
@Service
public class RabbitSendMqServiceImpl   {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Value("${whale.rabbitmq.exchange}")
    private String exchange;

    @Value("${whale.rabbitmq.routingKey}")
    private String routingKey;


    public boolean send(String outTradeNo) {
            log.info("RabbitMq 发送消息:{}",outTradeNo);
            try {
                rabbitTemplate.convertAndSend(exchange, routingKey, outTradeNo);
                return true;
            }catch (Exception e){
                log.error("RabbitMq 发送消息失败:{}",e);
                return false;
            }
    }
}
